package com.huzz.util.body;

import java.io.Serializable;

/**
 * @Name 数据+操作成功状态 数据包
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-04-2023/4/25 16:42
 */
public class DataBox<T> implements Serializable {

    /** 成功true | 失败 false */
    private boolean succeed;

    /** 数据 */
    private T data;

    public DataBox(boolean succeed, T data) {
        this.succeed = succeed;
        this.data = data;
    }


    public boolean isSucceed() {
        return succeed;
    }

    public T data() {
        return data;
    }

    public static<T> DataBox<T> succeedBuilder(T data) {
        return new DataBox<T>(true, data);
    }


    public static<T> DataBox<T> failedBuilder(T data) {
        return new DataBox<T>(false, data);
    }

    public static<T> DataBox<T> builder(boolean predicate, T succeedData, T failedData) {
        return predicate ? new DataBox<T>(true, succeedData) : new DataBox<T>(false, failedData);
    }

}
